<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<DecisionMaking.BusinessLogic.Model.ReportModel>" MasterPageFile="~/Views/Shared/Site.Master" %>
<%@ Import Namespace="DecisionMaking.Domain.Reports" %>

<asp:Content runat="server" ContentPlaceHolderID="TitleContent">Average Proportion of Correct Inferences report</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="MainContent">
    <% using (Html.BeginForm("AverageProportionOfCorrectInferences", "Reports", FormMethod.Get)) { %>
        <fieldset>
            <legend>Criteria</legend>
            <%=Html.Hidden("Execute", true) %>
            <p class="field-multi-line field-combo">
                <%= Html.LabelFor(m => m.EnvironmentId) %>
                <%= Html.DropDownListFor(m => m.EnvironmentId, new SelectList(Model.Environments, "Id", "Name"), "") %>
            </p>
            <p class="field-multi-line field-combo">
                <%= Html.LabelFor(m => m.SimulationId) %>
                <%= Html.DropDownListFor(m => m.SimulationId, new SelectList(Model.Simulations, "Id", "ExecutionDate"), "")%>
            </p>
            <p class="field-multi-line field-combo">
                <%= Html.LabelFor(m => m.DefinitionId) %>
                <%= Html.DropDownListFor(m => m.DefinitionId, new SelectList(Model.AlgorithmDefinitions, "Id", "Name"), "") %>
            </p>
            <p>
                <input type="submit" value="View" />
            </p>            
        </fieldset>
    <% } %>  
    <% if (ViewData["report"] != null) { %>
    <table>
        <thead>
            <tr>
                <th></th>
                <th colspan="7">% of cue values known</th>
            </tr>
            <tr>
                <th>Algorithm</th>
                <th>0</th>
                <th>10</th>
                <th>20</th>
                <th>50</th>
                <th>75</th>
                <th>100</th>
                <th>Average</th>
            </tr>
        </thead>
        <tbody>
        <%
        var entries = (IList<CompetitionResultReportEntry>) ViewData["report"];

        var query = entries
            .GroupBy(e => e.Algorithm)
            .Select(g => new {
                Algorithm = g.Key,
                Zero = g.Where(e => e.PctOfCueValuesKnown == 0).Sum(e => e.AvgCorrectInferences),
                Ten = g.Where(e => e.PctOfCueValuesKnown == 10).Sum(e => e.AvgCorrectInferences),
                Twenty = g.Where(e => e.PctOfCueValuesKnown == 20).Sum(e => e.AvgCorrectInferences),
                Fifty = g.Where(e => e.PctOfCueValuesKnown == 50).Sum(e => e.AvgCorrectInferences),
                SeventyFive = g.Where(e => e.PctOfCueValuesKnown == 75).Sum(e => e.AvgCorrectInferences),
                OneHundred = g.Where(e => e.PctOfCueValuesKnown == 100).Sum(e => e.AvgCorrectInferences),
                Average = g.Average(e => e.AvgCorrectInferences)
            });
            
        %>
        <% foreach(var entry in query) { %>
            <tr>
                <td><%=entry.Algorithm %></td>
                <td><%=entry.Zero %></td>
                <td><%=entry.Ten %></td>
                <td><%=entry.Twenty %></td>
                <td><%=entry.Fifty %></td>
                <td><%=entry.SeventyFive %></td>
                <td><%=entry.OneHundred %></td>
                <td><%=entry.Average %></td>
            </tr>
        <% } %>
        </tbody>
    </table>
    <% } %>
</asp:Content>
